{extend name="base/common"}

{block name="style"}
<link href="/static/summernote/summernote.css" rel="stylesheet">
<link href="/static/bootstrap-fileinput/css/fileinput.min.css" rel="stylesheet">

<style type="text/css">
    .note-editor.note-frame { border-radius: 0; border:0; margin-bottom: 0; }

</style>

{/block}

{block name="page-header"}

{/block}

{block name="main"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="mail-box-header">
            <h2>
                <span style="color:#337ab7">企业信息</span>|<a href="{:Url('product')}?id={$companyInfo.id}" style="color:inherit">产品及服务</a>
            </h2><br><br><br>
            <div>
                <div class="row clearfix">
                    <div class="col-md-10 column">
                        <div class="col-md-2 column">
                            <h3>企业头像</h3>
                        </div>
                        <div class="col-md-10 column">
                            <input  type="file" class="file input-file"><br>
                            <sapn>
                                <a class="front_cover" href="#">
                                    <img class="front_cover_img" src="{$companyInfo.img}" width="100px"/>
                                </a>
                            </sapn>
                        </div>

                        <div class="col-md-2 column"><h3>联系电话</h3>
                        </div >
                        <div class="col-md-10 column">
                            <input type="number" class="form-control"   name="phone" value="{$companyInfo.mobile}" />
                            <sapn style="height:40px;display: block" >
                            </sapn>
                        </div >
                        <div class="col-md-2 column"><h3>企业介绍</h3></div>
                        <div class="col-md-10 column">
                            <div class="mail-text h-200">
                                <div class="summernote">{$companyInfo->present}</div>
                                <div class="clearfix"></div>
                                <input type="hidden" name="content">
                                <input type="hidden" name="id" value="{$companyInfo->id}">
                            </div>
                            <sapn style="height:40px;display: block" >
                            </sapn>
                        </div>
                        <div class="col-md-2 column"><h3>关于我们</h3></div>
                        <div class="col-md-10 column">
                            <div class="mail-text h-200">
                                <div id="summernote" id="aboutus">{$companyInfo->about_us}</div>
                                <div class="clearfix"></div>
                            </div>
                        </div>
                        <div class="col-md-12 column "><br>
                            <a href="{:Url('index')}" class="btn btn-white btn-sm" style="float:right ;margin-left:5px ;" data-toggle="tooltip" data-placement="top"><i class="fa fa-times"></i> 关闭</a>
                            <a class="btn btn-sm btn-primary " style="float:right" onclick="companyMobile()"><i class="fa fa-reply"></i>&nbsp;发送</a>

                        </div>
                    </div>
                    </div>
            </div>
        </div>
    </div>
</div>
<input type="hidden" name="front_cover" value="">
{/block}

{block name="script"}
<script src="/static/summernote/summernote.min.js"></script>
<script src="/static/summernote/lang/summernote-zh-CN.js"></script>
<script src="/admin/js/plugins/iCheck/icheck.min.js"></script>
<script src="/static/bootstrap-fileinput/js/fileinput.min.js"></script>
<script src="/static/bootstrap-fileinput/themes/fa/fa.js"></script>
<script src="/static/bootstrap-fileinput/js/locales/zh.js"></script>
<script src="/static/js/jQuery-imgBox/jquery.imgbox.js"></script>
<script>
    $(document).ready(function(){
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });
        $(".check-all").on("ifChanged",function(){
            $("tbody").find(".ids").iCheck("toggle");
        });

        function sendFile(file) {
            var data = new FormData();
            data.append("file_data", file);
            $.ajax({
                data: data,
                type: "POST",
                url: "{:Url('Upload/picture')}",
                cache: false,
                contentType: false,
                processData: false,
                success: function(response) {
                    var data = $.parseJSON(response);
                    $(".summernote").summernote('insertImage', data.data, 'image name'); // the insertImage API
                }
            });
        }
        $('.summernote').summernote({
            lang: 'zh-CN',
            height: 300,
            minHeight: 210,
            callbacks: {
                onImageUpload: function (files) { //the onImageUpload API
                    img = sendFile(files[0]);
                }
            }
        });
        $('#summernote').summernote({
            lang: 'zh-CN',
            height: 300,
            minHeight: 210,
            callbacks: {
                onImageUpload: function (files) { //the onImageUpload API
                    img = sendFile(files[0]);
                }
            }
        });



    });


    $(".input-file").fileinput({
        showPreview: false,
        language: 'zh', //设置语言
        uploadUrl: '{:Url("Upload/picture")}', //上传的地址
        allowedFileExtensions: ['png','jpg','gif','png','jpeg'],
        maxFileSize: 1024 * 200,
    }).on("filebatchselected", function(event, files) {
        $(this).fileinput("upload");
    }).on('fileuploaded', function(event, data, previewId, index) {
        var response = $.parseJSON(data.response);
        if(response.code == 1) {
            $("input[name='front_cover']").val(response.data);
            $('.front_cover_img').attr('src',response.data);
        } else {
            updateAlert(response.msg, 'warning');
        }
    });

    $(".front_cover").imgbox({
        overlayShow: false,
        hideOnContentClick: true,
        slideshow: false,
        theme: 'dark',
        alignment: 'center',       // Position - may be auto OR center.
        allowMultiple: false,
    });
    /*添加企业信息*/
    function companyMobile(){
        var image=$("input[name='front_cover']").val();
        var phone = $("[name='phone']").val();
        var contents =$('#summernote').summernote('code');
        var presents =$('.summernote').summernote('code');
        $.ajax({
            type:"POST",
            url:"{:Url('Company/changeinfo')}",
            data:{id:'{$companyInfo.id}',img:image,mobile:phone,images:'{$companyInfo.img}',about_us:contents,present:presents},
            success:function (data) {
                if(data.code==1){
                    updateAlert(data.msg+ ' 页面即将自动跳转~','success');
                    setTimeout(function(){
                        location.href=data.url;
                    },3000);
                }else {
                    updateAlert(data.msg,"error");
                }
            }
        });
    }
</script>
{/block}